package top.lixunda.ecommerce.server.good.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import top.lixunda.commerce.common.core.entity.MessageObject;
import top.lixunda.common.utils.ObjectValidators;
import top.lixunda.ecommerce.server.business.BaseController;
import top.lixunda.ecommerce.server.good.api.controller.IOrderApplyController;
import top.lixunda.ecommerce.server.good.api.entity.vo.OrderApplyWithOrderVO;
import top.lixunda.ecommerce.server.good.service.IOrderApplyService;

/**
 * 订单申请操作接口实现
 *
 * @author lixunda
 * @version time:2020/3/3 16:24
 */
@Slf4j
@RestController
public class OrderApplyController extends BaseController implements IOrderApplyController {

    private final IOrderApplyService orderApplyService;

    @Autowired
    public OrderApplyController(IOrderApplyService orderApplyService) {
        this.orderApplyService = orderApplyService;
    }

    /**
     * 店铺调用，根据订单id查询未处理的订单申请数据
     *
     * @param id 订单编号
     * @return 返回申请数据
     */
    @Override
    public MessageObject<OrderApplyWithOrderVO> queryOrderApplyByOrderId(Integer id) {
        OrderApplyWithOrderVO orderApplyDO = orderApplyService.queryOrderApplyByOrderId(id);
        return ObjectValidators.isEmpty(orderApplyDO) ? getErrorMessageObject("申请不存在", null) :
                getSuccessMessageObject("获取数据成功", orderApplyDO);
    }

}
